<template>
	<view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				shop_id: "",
				issm: 0,
				ztnum: "",
				zth: "",
				zhuimoney: 0
			}
		},
		async onLoad(options) {
			this.shop_id = options.id
			this.issm = options.issm
			this.ztnum = options.ztnum
			this.zth = options.zth
			await this.smShoptableCl()
		},
		methods: {
			getkzInfo() {
				this.http.request('/api/shop/shop', 'POST', {
					shop_id: this.shop_id,
					shoptable_id: this.zth
				}).then(res => {
					let data = res.data
					let opentable_status = data.opentable_status
					opentable_status //0非開桌點餐,1開桌點餐
					if (opentable_status == 1) { //開桌點餐
						if (data.shoptableinfo.order_goods_id) { //如果存在id直接跳轉點餐
							uni.setStorageSync("reservation_order_id", data.shoptableinfo.order_goods_id)
							uni.redirectTo({
								url: "/pages_order/selectGoodsList?id=" + this.shop_id
							})
						} else { //如果不存在提示用戶
							this.http.modal('提示', "請到櫃檯開桌之後點餐", false, (resp) => {
								if (resp) {
									uni.reLaunch({
										url: "/pages/index/index"
									})
								}
							})
						}
					} else {
						if (data.shoptableinfo.order_goods_id) { //如果存在id直接跳轉點餐
							uni.setStorageSync("reservation_order_id", data.shoptableinfo.order_goods_id)
							uni.redirectTo({
								url: "/pages_order/selectGoodsList?id=" + this.shop_id
							})
						} else { //如果不存在跳轉商家首頁
							uni.navigateTo({
								url: "/pages_index/shopInfo?id=" + this.shop_id +
									"&issm=1" + "&ztnum=" + this.ztnum +
									"&zth=" + this.zth
							})
						}
					}
				})
			},
			smShoptableCl() {
				this.http.request('/api/ordergoods/smShoptableCl', 'GET', {
					shoptable_id: this.zth
				}).then(res => {
					if(res.code==1){
						let orderinfo = res.data.orderinfo
						if(orderinfo.zhuimoney!=0 && orderinfo.sk_type==1){//跳转支付画面
							uni.redirectTo({
								url: "/pages_index/payment?msg=" + encodeURIComponent(JSON.stringify({
									id: orderinfo.id,
									paymoney: orderinfo.zhuimoney,
									order_type: 1,
									shop_id: orderinfo.shop_id,
									call_no: orderinfo.call_no
								}))
							})
							return false
						}
					}else{
						this.getkzInfo()
					}
				})
			},


		}
	}
</script>

<style>

</style>